# Copyright (c) Meta Platforms, Inc. and affiliates.

load("@fbcode_macros//build_defs:native_rules.bzl", "buck_filegroup")
load("@fbsource//tools/build_defs:manifold.bzl", "manifold_get")
load("../defs.bzl", "zs_cxxbinary")

oncall("data_compression")

LAX_FLAGS = [
    "-Wno-cast-qual",
    "-Wno-sign-conversion",
    "-Wno-float-equal",
    "-Wno-switch-enum",
    "-Wno-undef",
    "-Wno-gnu-zero-variadic-macro-arguments",
    "-Wno-shorten-64-to-32",
]

# violates a bunch of zs strict flags in included external headers
SRC_FILE_FLAGS = {
    "e2e/e2e_json_extract.cpp": LAX_FLAGS,
    "e2e/e2e_parse.cpp": LAX_FLAGS,
    "e2e/e2e_thrift.cpp": LAX_FLAGS,
}

zs_cxxbinary(
    name = "benchmark",
    srcs = [(
        src_file,
        SRC_FILE_FLAGS.get(src_file, []),
    ) for src_file in glob([
        "**/*.cpp",
    ])],
    headers = glob([
        "**/*.h",
    ]),
    resources = {
        "corpus": ":benchmark_corpora",
    },
    deps = [
        "..:zstronglib",
        "../custom_transforms/json_extract:json_extract",
        "../custom_transforms/json_extract/tests:json_extract_test_data",
        "../custom_transforms/parse:parse",
        "../custom_transforms/parse/tests:parse_test_data",
        "../custom_transforms/thrift:thrift_lib",
        "../custom_transforms/thrift/tests:thrift_test_utils",
        "../tests/datagen:datagen",
        "../tools:zstrong_ml",
        "fbsource//third-party/benchmark:benchmark",
        "fbsource//third-party/fmt:fmt",
        "fbsource//xplat/tools/cxx:resources",
        "unitBench:sao_graph",
        "//folly:demangle",
        "//folly:dynamic",
        "//folly:json",
    ],
)

buck_filegroup(
    name = "benchmark_corpora",
    srcs = [
        ":sao",
    ],
)

manifold_get(
    name = "sao",
    out = "silesia/sao",
    api_key = "data_compression_corpora-key",
    artifact_path = "tree/silesia/sao",
    bucket_name = "data_compression_corpora",
    sha1 = "f1244afc9eaecb66d186e54926e4100e6662b0f5",
    timeout_msec = 120000,
    visibility = ["PUBLIC"],
)
